import React from 'react'
import { HashRouter, Route, Redirect, Switch } from 'react-router-dom'
//客户端版路由


import UrlIndex from './RouterIndex'
class MyRouter extends React.Component {
    constructor() {
        super()
        this.state = {

        }
    }
    showRouter = (Url) => {
        // console.log(Url);
        return Url.map(item => {

            if (item.redirect && item.children === undefined) {
                // console.log(11111);
                return <Route path={item.path} key={item.name} exact render={() => <Redirect to={item.redirect} />} />
            }
            else
                if (item.children) {
                    // console.log(22222);
                    return <Route path={item.path} key={item.name} render={() =>
                        <item.component>
                            {this.showRouter(item.children)}
                            <Route path={item.path} exact key={item.name} render={() => <Redirect to={item.children[0].path} />} />
                        </item.component>} />
                }
                else {
                    // console.log(3333);
                    return <Route path={item.path} key={item.name} component={item.component} />
                }

        })
        // console.log(nais);

    }
    render() {

        return (
            /* html */
            <HashRouter>
                <Switch>
                    {this.showRouter(UrlIndex)}

                    {/*   <Route path='/Home' render={() =>
                        <Home>
                            <Route path='/Home/Main' render={() =>
                                <Main>

                                </Main>} />
                            <Route path='/Home/Order' render={() =>
                                <Order>
                                </Order>} />
                            <Route path='/Home/MyInfo' render={() =>
                                <MyInfo>
                                </MyInfo>} />
                            <Route path='/Home/StoreList' component={StoreList} />
                            <Route path='/Home' exact render={() => <Redirect to='/Home/Main' />} />


                        </Home>} />

                    <Route path='/' exact render={() => <Redirect to='/Home' />} /> */}
                </Switch>
            </HashRouter>
        )
    }
}

export default MyRouter